package com.zensun.framework.config;

import com.zensun.common.constant.Constants;
import com.zensun.common.utils.weixin.SubscribeMessageUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class RedisKeyExpirationListener extends KeyExpirationEventMessageListener {

    public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
        super(listenerContainer);
    }

    /**
     * redis数据失效事件，进行数据处理
     *
     * @param message
     * @param pattern
     */
    @Override
    public void onMessage(Message message, byte[] pattern) {
        // message.toString()------获取失效的key
        String expiredKey = message.toString();
        if (expiredKey.contains(Constants.OVER_TIME_ORDER)) {
            String[] split = expiredKey.split(":");
            Long orderId = Long.valueOf(split[1]);
            String openId = split[2];
            String token = SubscribeMessageUtils.getAccessToken();
//            SubscribeMessageUtils.overTimeToPurifierSubscribe(token, openId, orderId, orderInfo.getItemName(), orderInfo.getReserveTime(), orderInfo.getCneeProject() + " " + orderInfo.getCneeAddress());
            log.info("===========>保洁超时未签到：订单ID：{}，保洁OpenID：{}", orderId, openId);

        }


    }
}
